<template>
  <div class="container">
    <!-- 面包屑 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/index' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>一卡通管理</el-breadcrumb-item>
      <el-breadcrumb-item>申请列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片 -->
    <el-card>
      <!-- alert提示 -->
      <el-alert title="tips:信息宝贵，谨慎操作" type="success" :closable="false"></el-alert>
      <!-- 搜索框 -->
      <!-- <el-row :gutter="30">
        <el-col :span="12">
          <el-input placeholder="请输入内容" v-model="queryInfo.keyWord" clearable @clear="getCardList">
            <el-button slot="append" icon="el-icon-search" @click="getCardList"></el-button>
          </el-input>
        </el-col>
      </el-row> -->
      <!-- table -->
      <el-table :data="cardList" border stripe>
        <el-table-column type="index"></el-table-column>
        <el-table-column label="姓名" prop="studentName"></el-table-column>
        <el-table-column label="校号" prop="studentNum"></el-table-column>
        <el-table-column label="院系" prop="department"></el-table-column>
        <el-table-column label="班级" prop="classes"></el-table-column>
        <el-table-column label="手机号" prop="studentPhone"></el-table-column>
        <el-table-column label="同意申请">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" @click="agreeApply(scope.row)">同意申请</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
import commonServe from '../../api/services/common.serve'
export default {
  data() {
    return {
      queryInfo: {
        keyWord: '',
        pageSize: 10,
        pageIndex: 1
      },
      cardList: []
    }
  },
  created() {
    this.getCardList()
  },
  methods: {
    // 获取待审核列表
    getCardList() {
      commonServe.getAuditList().then((res) => {
        console.log(res)
        if (res.code === 200) {
          this.cardList = res.data.list
        }
      })
    },
    // 同意用户一卡通申请
    async agreeApply(val) {
      console.log(val)
      const confirmResult = await this.$confirm('确认同意用户的一卡通申请', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).catch((err) => err)
      // 点击确认返回字符串confirm
      // 点击取消返回字符串cancel
      console.log(confirmResult)
      if (confirmResult !== 'confirm') {
        return this.$message.info('取消同意用户的一卡通申请')
      }
      // 接口
      commonServe
        .agreeOpenCard(val.id)
        .then((res) => {
          console.log(res)
          if (res.code === 200) {
            this.$message.success('成功为' + val.studentName + '开通校园一卡通')
            this.getCardList()
          } else {
            this.$message.warning('开通失败')
          }
        })
        .catch((err) => {
          this.$message.warning(err.message)
        })
    }
  }
}
</script>

<style lang="less" scoped></style>
